<template>
	<view class="flex main-box">

		<!-- <image class="invitebgs" v-if="needpiclist" :src="$oss(needpiclist)" mode="heightFix"></image>	 -->
		<view class="swiperBox">
			<u-swiper :list="needpiclist" height="100%"  @change="change" previousMargin="30" nextMargin="30" circular :autoplay="false" radius="5"
				bgColor="#ffffff"></u-swiper>
		</view>
		<!-- #ifdef APP-PLUS||MP -->
		<view class="choose flex">
			<view class="choose_item flex" @click="sharelj">
				<image src="../../static/pages_my/lj.png" mode=""></image>
				<view class="">分享链接</view>
			</view>
			<view class="shu">

			</view>
			<view class="choose_item flex" @click="download(needpic)">
				<image src="../../static/pages_my/lj.png" mode=""></image>
				<view class="">保存图片</view>
			</view>
			<view class="shu">

			</view>
			<view class="choose_item flex" @click="sharepic">
				<image src="../../static/pages_my/share.png" mode=""></image>
				<view class="">分享海报</view>
			</view>
		</view>
		<!-- #endif -->
		<!-- #ifdef H5 -->
		<view class="choose">
			<view class="choose_item flex-cneter" @click="$copy(needurl)">
				<image src="../../static/pages_my/lj.png" mode=""></image>
				<view class="">分享链接</view>
			</view>
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
import config from '../../uni_modules/uview-ui/libs/config/config'
	export default {
		data() {
			return {
				info: {},
				needurl: '',
				needpiclist: [],
				needpic:'',
				// config: this.$store.state.config,
			}
		},
		onLoad() {
			this.init()
		},
		computed: {
			config() {
				return this.$store.state.config
			}
		},
		methods: {
			change(e){
				this.needpic = this.needpiclist[e.current]
			},
			getInfo() {
				
				this.$api.post('/index', {}).then(res => {
					uni.hideLoading();
					if (res.code == 1) {
						if (res.data.usertype == 0) {
							this.needurl = this.info.url
							this.needpiclist = this.info.imgInfo.url
						} else if (res.data.usertype == 1) {
							this.needurl = this.info.business_url
							this.needpiclist = this.info.imgInfo.business_url
						} else if (res.data.usertype == 5) {
							this.needurl = this.info.channel_url
							this.needpiclist = this.info.imgInfo.channel_url
						} else if (res.data.usertype == 6) {
							this.needurl = this.info.sales_url
							this.needpiclist = this.info.imgInfo.sales_url
						}
						this.needpic = this.needpiclist[0]
					}
				}).catch((res) => {
					uni.hideLoading();
				})
			},
			sharepic() {
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 2,
					imageUrl: this.needpic,
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			sharelj() {
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 0,
					href: this.needurl,
					title: "分享",
					summary: `我正在使用${config.user_name}，赶紧跟我一起来体验！`,
					imageUrl: this.needpic,
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			download(url) {
				uni.downloadFile({
					url: this.$oss(url), //仅为示例，并非真实的资源
					success: (res) => {
						if (res.statusCode === 200) {
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success: function() {
									uni.$u.toast(`保存成功`)

								}
							});
						}
					}
				});
			},
			copya(url) {
				uni.previewImage({
					urls: [url]
				})
			},
			init() {
				uni.showLoading({
					title: '生成中...',
					mask: true
				});
				this.$api.post('/share', {}).then(res => {
					this.info = res.data
					this.getInfo()
				}).catch((res) => {
					uni.hideLoading();
				})
			},
		}
	}
</script>

<style lang="scss">
	.main-box {
		flex-direction: column;
		height: calc(100vh - var(--window-bottom) - var(--window-top));
		padding-top: var(--status-bar-height);
		box-sizing: border-box;
		padding-top: 20rpx;
	}

	.invitebgs {
		margin: 0 auto;
		border-radius: 20rpx;
		flex: 1;
	}
	.swiperBox{
		flex: 1;
		
	}

	.choose {
		bottom: 0rpx;
		left: 5%;
		box-sizing: border-box;
		justify-content: space-between;
		width: 90vw;
		margin: 30rpx auto;
		border-radius: 40rpx;
		background-color: #fff;
		box-shadow: 0rpx 0rpx 10rpx 0rpx #F0F0F0;
		padding: 30rpx;

		.shu {
			width: 3rpx;
			height: 30rpx;
			border-radius: 30rpx;
			background-color: #E7E7E7;
		}

		.choose_item {
			align-items: center;

			image {
				margin-right: 10rpx;
				width: 24rpx;
				height: 24rpx;
			}
		}
	}
</style>